﻿package mortal.game.view.investmentProject
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.ui.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.rebate.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class InvestmentModule extends BaseWindow
    {
        private var _dayTxt:BitmapNumberText;
        private var _investmentBtn:GLoadingButton;
        private var _rechargeBtn:GLoadingButton;
        private var _friendlyTipsTxt:GTextFiled;
        private var _tips:GTextFiled;
        private var _consumeBox:GConsumeBox;
        protected var _day:BitmapNumberText;
        protected var _hour:BitmapNumberText;
        protected var _min:BitmapNumberText;
        protected var _secView:SecTimerView;
        private var _investInfo:SInvestInfo;
        private var _btnArr:Array;
        private var _isGetIconArr:Array;
        private var _arr:Array;
        private var _posArr:Array;

        public function InvestmentModule(param1:ILayer = null)
        {
            this._btnArr = new Array();
            this._isGetIconArr = new Array();
            this._arr = [0, 1088, 248, 308, 368, 428, 488, 548];
            this._posArr = [380, 541, 521, 495, 465, 445, 426];
            super(param1);
            this.setSize(890, 604);
            this.title = Language.getString(35322);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.investmnetTitleBg, 5, 35, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.investmentContentBg, 5, 215, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.investmentTitle, -5, 183, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.TimeCountDowmTxt, 267, 239, this));
            this._dayTxt = UIFactory.bitmapNumberText(133, 172, "investmentNum.png", 24, 30, -8, null, 9, BitmapNumberText.Mid);
            this._day = UIFactory.bitmapNumberText(400, 238, "QuestionCopyNum.png", 18, 25, -2, this, 13, 1);
            this._day.text = "2";
            this._hour = UIFactory.bitmapNumberText(455, 238, "QuestionCopyNum.png", 18, 25, -2, this, 13, 1);
            this._hour.text = "12";
            this._min = UIFactory.bitmapNumberText(526, 238, "QuestionCopyNum.png", 18, 25, -2, this, 13, 1);
            this._min.text = "59";
            this._consumeBox = UIFactory.gConsumeBox("", 705, 176, 0, this);
            this._consumeBox.addItem(ConsumeData.ShowMoneyType, EPriceUnit._EPriceUnitGold, 0, Language.getString(35323), "1");
            this._investmentBtn = UIFactory.gLoadingButton(ResFileConst.investmentBtn, 595, 228, 141, 43, this);
            this._investmentBtn.configEventListener(MouseEvent.CLICK, this.buttomClickHandler);
            this._rechargeBtn = UIFactory.gLoadingButton(ResFileConst.investmentRechargeBtn, 745, 228, 141, 43, this);
            this._rechargeBtn.configEventListener(MouseEvent.CLICK, this.buttomClickHandler);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.size = 15;
            this._friendlyTipsTxt = UIFactory.gTextField("", 290, 580, 330, 23, null, _loc_1);
            _loc_1 = GlobalStyle.textFormatItemGreen;
            _loc_1.underline = true;
            this._tips = UIFactory.gTextField(Language.getString(35324), 828, 285, 80, 20, this, _loc_1, true);
            this._tips.reactionTime = 10;
            this._tips.toolTipData = Language.getStringByParam(35325, this._arr[0] + this._arr[1], this.getLeftMoney(1, true, true));
            this.createBtn();
            this.update();
            this._secView = UIFactory.secTimeView(Language.getString(30055), 610, 341, 0, 0, null);
            this._secView.configEventListener(EventName.SecViewTimeChange, this.onTimeChangeHd);
            this.setTimeCountDown();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._dayTxt.dispose(param1);
            this._dayTxt = null;
            this._investmentBtn.dispose(param1);
            this._investmentBtn = null;
            this._friendlyTipsTxt.dispose(param1);
            this._friendlyTipsTxt = null;
            this._tips.dispose(param1);
            this._tips = null;
            this._day.dispose(param1);
            this._day = null;
            this._hour.dispose(param1);
            this._hour = null;
            this._min.dispose(param1);
            this._min = null;
            this._secView.dispose();
            this._secView = null;
            this._rechargeBtn.dispose(param1);
            this._rechargeBtn = null;
            this._consumeBox.dispose(param1);
            this._consumeBox = null;
            this._investInfo = null;
            this._btnArr.length = 0;
            this._isGetIconArr.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function createBtn() : void
        {
            var _loc_1:GLoadingButton = null;
            var _loc_2:GImageBitmap = null;
            var _loc_3:int = 0;
            while (_loc_3 < this._posArr.length)
            {
                
                _loc_1 = UIFactory.gLoadingButton(ResFileConst.RectGetBtn, 49 + _loc_3 * 118, this._posArr[_loc_3], 68, 25, this);
                _loc_1.name = "btn_" + _loc_3;
                _loc_1.configEventListener(MouseEvent.CLICK, this.getInvestment);
                _loc_1.filters = [FilterConst.colorFilter2];
                _loc_1.mouseEnabled = false;
                this.pushUIToDisposeVec(_loc_1);
                this._btnArr.push(_loc_1);
                _loc_2 = UIFactory.gImageBitmap("", 51 + _loc_3 * 118, this._posArr[_loc_3] - 20, this);
                this.pushUIToDisposeVec(_loc_2);
                this._isGetIconArr.push(_loc_2);
                _loc_3++;
            }
            return;
        }// end function

        protected function setTimeCountDown() : void
        {
            var _loc_1:* = this.getLeftTime();
            this._secView.stop();
            if (_loc_1 < 0)
            {
                return;
            }
            this._secView.setLeftTime(_loc_1);
            return;
        }// end function

        protected function getLeftTime() : Number
        {
            return RebateUtil.getTodayLeftTime();
        }// end function

        protected function onTimeChangeHd(event:DataEvent) : void
        {
            if (this._secView == null)
            {
                return;
            }
            if (this._secView.secTimerViewData == null)
            {
                this._secView.stop();
                return;
            }
            var _loc_2:* = this._secView.secTimerViewData.hh();
            var _loc_3:* = this._secView.secTimerViewData.mm();
            this._hour.text = "" + _loc_2;
            this._min.text = "" + _loc_3;
            return;
        }// end function

        private function buttomClickHandler(event:MouseEvent) : void
        {
            if (event.target == this._investmentBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Investment, EInvestType._EInvestTypeResigst));
            }
            else if (event.target == this._rechargeBtn)
            {
                GameUtil.gotoRecharge(ModuleTypeConst.InvestmentModule);
            }
            return;
        }// end function

        private function getInvestment(event:MouseEvent) : void
        {
            var _loc_2:* = int((event.target as GLoadingButton).name.slice(4)) + 1;
            var _loc_3:Object = {operType:EInvestOper._EInvestGetToday, type:EInvestType._EInvestTypeResigst, day:_loc_2};
            Dispatcher.dispatchEvent(new DataEvent(EventName.InvestmentGet, _loc_3));
            return;
        }// end function

        public function update() : void
        {
            var _loc_1:int = 0;
            var _loc_2:SInvestInfo = null;
            var _loc_3:GLoadingButton = null;
            var _loc_4:GImageBitmap = null;
            var _loc_5:int = 0;
            this._investInfo = Cache.instance.investment.getTodayInfoByType(EInvestType._EInvestTypeResigst);
            if (this._investInfo)
            {
                _loc_1 = Cache.instance.investment.getDaysByType(EInvestType._EInvestTypeResigst);
                this._investmentBtn.enabled = false;
                this._dayTxt.text = _loc_1.toString();
                this._friendlyTipsTxt.htmlText = Language.getStringByParam(31000, (7 - _loc_1).toString());
                this._day.text = "" + (7 - _loc_1);
                _loc_5 = 0;
                while (_loc_5 < this._btnArr.length)
                {
                    
                    _loc_3 = this._btnArr[_loc_5];
                    _loc_3.visible = true;
                    _loc_4 = this._isGetIconArr[_loc_5];
                    if ((_loc_5 + 1) > _loc_1)
                    {
                        _loc_3.filterEnabled = false;
                        _loc_4.imgUrl = "";
                    }
                    else
                    {
                        _loc_2 = Cache.instance.investment.getTodayInfoByType(EInvestType._EInvestTypeResigst, (_loc_5 + 1));
                        if (_loc_2.isGetToday)
                        {
                            _loc_4.imgUrl = ImagesConst.MonthInvestGetSuccess;
                            _loc_3.visible = false;
                        }
                        else
                        {
                            _loc_3.filterEnabled = true;
                            _loc_4.imgUrl = "";
                        }
                    }
                    _loc_5++;
                }
            }
            else
            {
                this._friendlyTipsTxt.htmlText = Language.getStringByParam(31000, (this._arr.length - 1));
                this._dayTxt.text = "1";
                this._investmentBtn.enabled = true;
                this._day.text = "" + (7 - ClockManager.instance.getLoginDayNumByPassZero());
            }
            return;
        }// end function

        private function getLeftMoney(param1:int, param2:Boolean, param3:Boolean) : int
        {
            var _loc_4:* = param3 ? (0) : (this._arr[0]);
            _loc_4 = _loc_4 + (param2 ? (0) : (this._arr[param1]));
            var _loc_5:* = param1 + 1;
            while (_loc_5 < this._arr.length)
            {
                
                _loc_4 = _loc_4 + this._arr[_loc_5];
                _loc_5++;
            }
            return _loc_4;
        }// end function

    }
}
